home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C++ / Applications / Muddweller 1.2 / source code / Externals / USizerView.h < prev    next >
Encoding:
C/C++ Source or Header  |  1992-02-26  |  18.6 KB  |  468 lines  |  [TEXT/MPS ]

  1. #ifndef  __USizerView__
  2. #define __USizerView__
  3.  
  4. /*    This unit implements views which can be divided into several resizable panes.
  5.     It also contains commands for resizing and splitting, as well as a splitter Control.
  6. */
  7.  
  8. #ifndef  __UMacApp__
  9. #include "UMacApp.h"
  10. #endif
  11.  
  12. #ifndef  __UArray__
  13. #include "UArray.h"
  14. #endif
  15.  
  16.  
  17.             /* Command Numbers */
  18.  
  19. const short cSizeViews            = 2300;                 /* For resizing panes in TSizerView */
  20.  
  21.             /* Miscellaneous */
  22.  
  23. const short kSplitVertically    = v;                    /* use with "whichWay" parameter of */
  24. const short kSplitHorizontally    = h;                    /* ISizerCommand */
  25.  
  26. const short kSizerThickness     = 3;                    /* default thickness of splitter bar */
  27. const short kMinSizerPane        = 60;                    /* default minimum pane size */
  28.  
  29. const short kVertSizingCursor    = 1300;                 /* CURSor IDs */
  30. const short kHorzSizingCursor    = 1301;
  31.  
  32. const Boolean kGetMinCoord        = TRUE;                    /* values for min parameter of GetSizerCoord */
  33. const Boolean kGetMaxCoord        = FALSE;
  34.  
  35. const Boolean kLocationVaries    = TRUE;                    /* values for fLocDeterminer fields */
  36. const Boolean kLocationFixed    = FALSE;                /* …of TSplitter */
  37.  
  38. const unsigned long kStdSplitter = 'splt';                /* resource signature for a TSplitter */
  39. const unsigned long kNoId        = '    ';                /* empty view id */
  40.  
  41.  
  42.     /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  43.  
  44. typedef VRect *VRectPtr;
  45. typedef enum {kLeftCoord, kRightCoord, kTopCoord, kBottomCoord} Coordinate;
  46.  
  47. class TVRectList : public TDynamicArray {
  48.     public:
  49.             /* This class represents an indexed list of VRects */
  50.  
  51.     virtual pascal void IVRectList(short initialSize);
  52.                 /* Initialize the list, making it big enough to contain initialSize VRects. */
  53.  
  54.     virtual pascal VRect At(ArrayIndex index);
  55.                 /* Return the VRect at the given list index. */
  56.  
  57.     virtual pascal void AtPut(ArrayIndex index, VRect *newItem);
  58.                 /* Set the VRect at the specified index to the given VRect. If index is greater
  59.                   than the number of elements in the list, expand the list accordingly. */
  60.  
  61.     virtual pascal void AtCoordPut(ArrayIndex index, Coordinate whichCoord, VCoordinate newCoord);
  62.                 /* Change a single coordinate of the specified VRect to the given value. */
  63.  
  64.     virtual pascal void AtSetVRect(ArrayIndex index, VCoordinate left, VCoordinate top,
  65.         VCoordinate right, VCoordinate bottom);
  66.                 /* Change the specified VRect’s coordinates to the given values. */
  67.  
  68.     virtual pascal void InsertBefore(ArrayIndex index, VRect *item);
  69.  
  70.     virtual pascal void Fields(pascal void (*DoToField)(StringPtr fieldName, Ptr fieldAddr, short 
  71.        fieldType, void *DoToField_StaticLink), void *DoToField_StaticLink);
  72.  
  73.     virtual pascal void DynamicFields(pascal void (*DoToField)(StringPtr fieldName, Ptr fieldAddr, short 
  74.        fieldType, void *DoToField_StaticLink), void *DoToField_StaticLink);
  75.  
  76. };
  77.  
  78.     /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  79.  
  80. class TSizerView : public TView {
  81.     public:
  82.             /* This class maintains multiple panes (subviews of itself) with movable
  83.               sizer rectangles between them. */
  84.  
  85.     TList *fPanes;                /* the subviews themselves */
  86.     TVRectList *fSetbacks;        /* the setbacks for the subpanes */
  87.     TVRectList *fSizerRects;    /* the sizer rectangles */
  88.     VCoordinate fMinPaneSize;    /* minimum width/height of a pane */
  89.     short fSizerThickness;        /* thickness of splitter */
  90.     struct TSplitter *fSplitter; /* NIL if no splitter */
  91.  
  92.                 /* Initialization methods */
  93.  
  94.     virtual pascal void Initialize();
  95.                 /* Initialize fields to NIL. Called by IObject. */
  96.  
  97.     virtual pascal void IRes(TDocument *itsDocument, TView *itsSuperView, Ptr *itsParams);
  98.                 /* Initialize a view created from templates. */
  99.  
  100.     virtual pascal void ISizerView(TDocument *itsDocument, TView *itsSuperView, VPoint *itsLocation,
  101.         VPoint *itsSize, SizeDeterminer itsHSizeDet, SizeDeterminer itsVSizeDet);
  102.                 /* Initialize a view created procedurally. */
  103.  
  104.     virtual pascal void InitLists();
  105.                 /* Create and initialize the various lists of subviews and VRects */
  106.  
  107.     virtual pascal void FixupPanes(Boolean equalSpacing);
  108.                 /* a/k/a “PostRes”: Call after IRes (NewTemplateWindow).
  109.                   Now that the subviews have been added, use them to initialize the
  110.                   setbacks and sizer rectangles to their default values.
  111.                   If equalSpacing is TRUE, make the panes of equal size;
  112.                   otherwise, try to locate the panes using their fLocations. */
  113.  
  114.     virtual pascal void Free();
  115.                 /* Free the setbacks and sizer list objects */
  116.  
  117.  
  118.                 /* Adding, drawing, resizing panes */
  119.  
  120.     virtual pascal void AddPane(TView *newPane, VCoordinate itsLocation, VRect *itsSetbacks);
  121.                 /* Install thePane at the specified location, shrinking any existing pane
  122.                   accordingly. */
  123.  
  124.     virtual pascal void AddEqualPane(TView *newPane, short itsPosition, VRect *itsSetbacks);
  125.                 /* Install thePane at the specified position, resizing all panes equally. */
  126.  
  127.     virtual pascal TView *DeletePane(short whichPane, short whichSizer);
  128.                 /* Delete the specified pane and sizer; expand the remaining pane and
  129.                   return it. */
  130.  
  131.     virtual pascal void Draw(Rect *area);
  132.                 /* General draw method: call DrawSizerRect for each sizer rectangle. */
  133.  
  134.     virtual pascal void DrawSizerRect(Rect *aRect);
  135.                 /* Do the direction-dependent drawing: must be overridden. */
  136.  
  137.     virtual pascal void InstallSetbacks(short whichPane, VRect *itsSetbacks);
  138.                 /* Use this method to set different setbacks than the default ones. */
  139.                 /* This unit defines three global rects for use in setbacks:
  140.                     gVertSBarSetback - Use when installing scroller subviews which
  141.                         have only a vertical scrollbar.
  142.                     gHorzSBarSetback - Use when installing scroller subviews which
  143.                         have only a horizontal scrollbar.
  144.                     gBothSBarSetback - Use when installing scroller subviews which
  145.                         have horiz AND vert scrollbars.
  146.                   You may also use MacApp's gZeroVRect to indicate that there is to be
  147.                   no setback at all. */
  148.         
  149.     virtual pascal VPoint MergedSize(TView *oldPane, TView *changedPane);
  150.                 /* Return the combined size of oldPane and changedPane. Must be overridden. */
  151.  
  152.     virtual pascal void SetPane(short whichSizer, VRect *itsSizerRect);
  153.                 /* The specified sizer has moved, so adjust the panes on either side of it */
  154.  
  155.     virtual pascal void SetPanes(TVRectList *newSizerRects, Boolean invalidate);
  156.                 /* All the sizers have moved, so adjust all the panes in the view */
  157.  
  158.     virtual pascal void SuperViewChangedSize(VPoint *delta, Boolean invalidate);
  159.                 /* Forces commit of any pending pane resize command. Generally this
  160.                   matters only on a window resize which normally would not commit a
  161.                   command; such a resize will force an additional pane resize so
  162.                   "Undo Pane Resize" (or Redo) ceases to make sense.*/
  163.  
  164.  
  165.                 /* Cursors and mice, etc. */
  166.  
  167.     virtual pascal struct TCommand *DoMouseCommand(Point *theMouse, EventInfo *info,
  168.         Point * hysteresis);
  169.                 /* If the mouse is in a sizer rectangle, create and return a TSizerCommand. */
  170.  
  171.     virtual pascal Boolean DoSetCursor(Point localPoint, RgnHandle cursorRgn);
  172.                 /* Draw the appropriate sizer cursor if necessary.  If the cursor resource
  173.                   is missing, default to the arrow. */
  174.  
  175.     virtual pascal void InvalidateFocus();
  176.                 /* Avoid traversing subviews; just set gFocusedView to NIL */
  177.  
  178.     virtual pascal void TrackConstrain(VPoint *anchorPoint, VPoint *previousPoint,
  179.                                                     VPoint *nextPoint);
  180.                 /* Constrain mouse tracking to my interior, allowing for the minimum pane size.
  181.                   Must be overridden: direction dependent. */
  182.  
  183.  
  184.                 /* Gettors and settors */
  185.  
  186.     virtual pascal CompareResult CompareViewLocations(TView *view1, TView *view2);
  187.                 /* Return the order of the two views by their location. This calculation
  188.                   is direction dependent, so it must be overridden. */
  189.  
  190.     virtual pascal short FindPane(TView *aView);
  191.                 /* Return the position (index) of aView in the fPanes list */
  192.  
  193.     virtual pascal TView *FindPaneAt(VPoint *theCoords);
  194.                 /* Return the pane at the given coordinates */
  195.  
  196.     virtual pascal short FindSizerPosition(VCoordinate *itsLocation);
  197.                 /* Given the desired coordinate for a new sizer rectangle, return its position
  198.                   (index) in the list of sizers, modifying itsLocation if necessary. */
  199.  
  200.     virtual pascal VRect GetDefaultSizerRect(short whichSizer);
  201.                 /* Return the VRect for the given sizer, assuming evenly spaced sizers. */
  202.  
  203.     virtual pascal VCoordinate GetMinPaneLength();
  204.                 /* Return the minimum width/height of a pane of this view. */
  205.  
  206.     virtual pascal VRect GetNextSizerRect(TView *aPane);
  207.                 /* Must be overridden */
  208.  
  209.     virtual pascal short GetNumberOfPanes();
  210.                 /* How many subviews do I have? */
  211.  
  212.     virtual pascal short GetNumberOfSizers();
  213.                 /* How many sets of sizer bars do I have? (Hint: number of panes - 1) */
  214.  
  215.     virtual pascal VCoordinate GetSizerCoord(short whichSizer, Boolean min);
  216.                 /* Return the left/top (min=T) or right/bottom (min=F) coordinate of the
  217.                     specified sizer rect.
  218.                   If whichSizer is larger than the number of sizers, return the width/height
  219.                     of the view.
  220.                   If whichSizer is 0, return 0. */
  221.  
  222.     virtual pascal VRect GetSizerRect(short whichSizer);
  223.                 /* Return the specified sizer rectangle. The count starts from the
  224.                   top/left at 1. */
  225.  
  226.     virtual pascal short GetSizerThickness();
  227.                 /* Return the thickness of the pane splitter rectangle. */
  228.  
  229.     virtual pascal short GetSizingCursor();
  230.                 /* Return the resource id of the cursor to use when sizing.
  231.                   Must be overridden. */
  232.  
  233.     virtual pascal VHSelect GetSplitDirection();
  234.                 /* Return the direction of the split: v or h. Defaults to h. */
  235.  
  236.     virtual pascal short IsPointInSizer(Point localPoint);
  237.                 /* Return the number of the sizer rect the localPoint is in, or 0 if none. */
  238.  
  239.     virtual pascal Boolean IsValidSplitPt(VPoint *aPoint);
  240.                 /* Return TRUE if the pane can be split at the given location. */
  241.  
  242.     virtual pascal VRect MakeSizerRect(VCoordinate itsLocation);
  243.                 /* Direction-dependent: must be overridden */
  244.  
  245.     virtual pascal void SetMinPaneLength(VCoordinate minLength);
  246.                 /* Set the minimum width/height of a pane of this view. */
  247.  
  248.     virtual pascal void SetSizerThickness(short thickness);
  249.                 /* Set the thickness of the pane splitter rectangle. */
  250.  
  251.     virtual pascal void SetSizerRect(short whichSizer, VRect *itsSizerRect);
  252.                 /* Change the specified sizerRect and invalidate both the old and new rectangles. */
  253.  
  254.     virtual pascal void Fields(pascal void (*DoToField)(StringPtr fieldName, Ptr fieldAddr, short 
  255.        fieldType, void *DoToField_StaticLink), void *DoToField_StaticLink);
  256. };
  257.  
  258.  
  259. class THorizontalSizer : public TSizerView {
  260.     public:
  261.             /* This view contains subviews which are stacked one on top of the other. */
  262.  
  263.     virtual pascal CompareResult CompareViewLocations(TView *view1, TView *view2);
  264.                 /* Tell whether view1 is above or below view2, by location. */
  265.  
  266.     virtual pascal void DrawSizerRect(Rect *aRect);
  267.                 /* Draw two parallel horizontal lines to represent the sizer rectangle. */
  268.  
  269.     virtual pascal VRect GetNextSizerRect(TView *aPane);
  270.  
  271.     virtual pascal VCoordinate GetSizerCoord(short whichSizer, Boolean min);
  272.  
  273.     virtual pascal VRect GetSizerRect(short whichSizer);
  274.  
  275.     virtual pascal short GetSizingCursor();
  276.                 /* Return the resource id of the cursor to display when it's over horizontal
  277.                   sizer bars. */
  278.  
  279.     virtual pascal Boolean IsValidSplitPt(VPoint *aPoint);
  280.  
  281.     virtual pascal VRect MakeSizerRect(VCoordinate itsLocation);
  282.                 /* Return the sizer VRect with the specified top coordinate. */
  283.  
  284.     virtual pascal void Resize(VCoordinate width, VCoordinate height, Boolean invalidate);
  285.                 /* Resize the panes proportionally. */
  286.  
  287.     virtual pascal void SetPane(short whichSizer, VRect *itsSizerRect);
  288.     
  289.     virtual pascal void SetPanes(TVRectList *newSizerRects, Boolean invalidate);
  290.                 /* Direction-dependent resizing. See description in the parent class. */
  291.  
  292.     virtual pascal void TrackConstrain(VPoint *anchorPoint, VPoint *previousPoint,
  293.                                                     VPoint *nextPoint);
  294.                 /* Constrain mouse tracking to my interior, allowing for the minimum pane size */
  295. };
  296.  
  297.  
  298.     /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  299.  
  300. class TSizerCommand : public TCommand {
  301.     public:
  302.         /* This command is for moving existing sizer bars, resizing the panes they separate. */
  303.  
  304.     TSizerView *fSizerView;            /* view in which to track sizers */
  305.     long fNewEdge;                    /* the new sizer rectangle location */
  306.     VRect fOldSizerRect;            /* the old sizer rectangle */
  307.     VHSelect fSplitDir;                /* direction of the split: h or v */
  308.     short fWhichSizer;                /* which sizer we’re tracking, */
  309.                                     /* …counting from the left or top */
  310.  
  311.     virtual pascal void ISizerCommand(TSizerView *itsSizerView, short whichSizer,
  312.         VHSelect whichWay);
  313.                 /* Add whichWay parameter so command doesn’t have to do a Member test on the
  314.                   sizer view */
  315.  
  316.     virtual pascal TCommand *TrackMouse(TrackPhase aTrackPhase, VPoint *anchorPoint, VPoint *
  317.         previousPoint, VPoint *nextPoint, Boolean mouseDidMove);
  318.  
  319.     virtual pascal void TrackFeedback(VPoint *anchorPoint, VPoint *nextPoint, Boolean turnItOn, 
  320.         Boolean mouseDidMove);
  321.  
  322.     virtual pascal void TrackConstrain(VPoint *anchorPoint, VPoint *previousPoint,
  323.                                                     VPoint *nextPoint);
  324.  
  325.     virtual pascal void DoIt();
  326.                 /* Compute the new sizer rectangle and resize the appropriate panes */
  327.  
  328.     virtual pascal void UndoIt();
  329.                 /* Set sizer rectangle back to its previous location, and resize panes */
  330.  
  331.     virtual pascal void RedoIt();
  332.                 /* DoIt again */
  333.  
  334.     virtual pascal void SetPenForFeedback(VPoint *aPoint);
  335.                 /* Set the pen pattern and size for showing feedback when tracking at the
  336.                   given point */
  337.  
  338.     virtual pascal void Fields(pascal void (*DoToField)(StringPtr fieldName, Ptr fieldAddr, short 
  339.        fieldType, void *DoToField_StaticLink), void *DoToField_StaticLink);
  340.  
  341. };    /* TSizerCommand */
  342.  
  343.     /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  344.  
  345. class TSplitterCommand : public TSizerCommand {
  346.     public:
  347.             /* This command is for creating new sizer bars using a splitter control. The pane
  348.               split by the new sizer is cloned, creating a new subview of the SizerView. */
  349.  
  350.     virtual pascal void ISplitterCommand(TSizerView *itsSizerView);
  351.                 /* Set fWhichSizer to 0, so that it tracks over the entire SizerView. */
  352.  
  353.     virtual pascal void TrackConstrain(VPoint *anchorPoint, VPoint *previousPoint,
  354.         VPoint *nextPoint);
  355.                 /* Override to do nothing, so that tracking will be constrained to the SizerView */
  356.  
  357.     virtual pascal void DoIt();
  358.                 /* Create the new pane via cloning and add it to the SizerView. */
  359.  
  360.     virtual pascal void SetPenForFeedback(VPoint *aPoint);
  361.                 /* Show a gray line when tracking outside areas where splitting is allowed. */
  362.  
  363.     virtual pascal TCommand *TrackMouse(TrackPhase aTrackPhase, VPoint *anchorPoint, VPoint *
  364.         previousPoint, VPoint *nextPoint, Boolean mouseDidMove);
  365.                 /* If the pane is not splittable at the mouse-up location, return NIL. */
  366.  
  367.     virtual pascal void Fields(pascal void (*DoToField)(StringPtr fieldName, Ptr fieldAddr, short 
  368.        fieldType, void *DoToField_StaticLink), void *DoToField_StaticLink);
  369. };
  370.  
  371.             
  372.     /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  373.  
  374. typedef enum {kResizeOK, kResizeNotOK, kDeleteSizer} SizerTracking;
  375.  
  376. class TDeSizerCommand : public TSizerCommand {
  377.     public:
  378.             /* This command is for moving or deleting existing sizer bars.
  379.               The SizerView must contain a splitter control. */
  380.  
  381.     VRect fResizeRect;            /* valid area for resizing */
  382.     Boolean fResizeOK;            /* characterize area of fSizerView… */
  383.                                 /* …we're tracking in */
  384.  
  385.     virtual pascal void IDeSizerCommand(TSizerView *itsSizerView, short whichSizer,
  386.                                                           VHSelect whichWay);
  387.  
  388.     virtual pascal void DoIt();
  389.                 /* If final mouse position was at either end of the SizerView,
  390.                   delete the sizer bars; otherwise, just resize. */
  391.  
  392.     virtual pascal void SetPenForFeedback(VPoint *aPoint);
  393.                 /* Set the pen to black, gray, or white, depending on where aPoint is. */
  394.  
  395.     virtual pascal void TrackConstrain(VPoint *anchorPoint, VPoint *previousPoint,
  396.         VPoint *nextPoint);
  397.                 /* Track over the entire SizerView, but keep track of whether nextPoint
  398.                   is a valid spot for the sizer bars to move to. */
  399.  
  400.     virtual pascal TCommand *TrackMouse(TrackPhase aTrackPhase, VPoint *anchorPoint, VPoint *
  401.         previousPoint, VPoint *nextPoint, Boolean mouseDidMove);
  402.                 /* Return NIL if trackRelease is in original sizer rect, or if trackRelease
  403.                   is outside the valid resizing area (but not in the sizer deletion area). */
  404.  
  405.     virtual pascal void Fields(pascal void (*DoToField)(StringPtr fieldName, Ptr fieldAddr, short 
  406.        fieldType, void *DoToField_StaticLink), void *DoToField_StaticLink);
  407. };
  408.  
  409.  
  410.     /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  411.  
  412. class TSplitter : public TControl {
  413.     public:
  414.     TSizerView *fSizerView;        /* the view that handles multiple panes */
  415.     Boolean fLocDeterminer[2];    /* T: adjust location coordinate */
  416.                                 /* …in SuperViewChangedSize */
  417.  
  418.     virtual pascal void IRes(TDocument *itsDocument, TView *itsSuperView, Ptr *itsParams);
  419.  
  420.     virtual pascal void ISplitter(TDocument *itsDocument, TView *itsSuperView,
  421.                                               VPoint *itsLocation, VPoint *itsSize);
  422.  
  423.     virtual pascal void IFinish(TView *itsSuperView);
  424.                 /* Finish up initialization by setting the fSizerView and fLocDeterminer fields.
  425.                   The latter are determined by the SizerView’s split direction. */
  426.  
  427.     virtual pascal void Draw(Rect *area);
  428.                 /* Default is just a black rectangle, like a splitter well */
  429.  
  430.     virtual pascal struct TCommand *DoMouseCommand(Point *theMouse, EventInfo *info,
  431.             Point * hysteresis);
  432.                 /* Override to return a TSplitterCommand. */
  433.  
  434.     virtual pascal long GetThickness();
  435.                 /* Return the thickness of the splitter control. */
  436.  
  437.     virtual pascal void SuperViewChangedSize(VPoint *delta, Boolean invalidate);
  438.                 /* Adjust the coordinates for which fLocDeterminer = T */
  439.  
  440.     virtual pascal void Fields(pascal void (*DoToField)(StringPtr fieldName, Ptr fieldAddr, short 
  441.        fieldType, void *DoToField_StaticLink), void *DoToField_StaticLink);
  442. };
  443.  
  444.  
  445.     /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  446.  
  447. extern pascal VRect gVertSBarSetback;        /* Use when installing scroller subviews which
  448.                                             have only a vertical scrollbar */
  449. extern pascal VRect gHorzSBarSetback;        /* Use when installing scroller subviews which
  450.                                             have only a horizontal scrollbar */
  451. extern pascal VRect gBothSBarSetback;        /* Use when installing scroller subviews which
  452.                                             have horiz AND vert scrollbars */
  453.  
  454. extern pascal TIntegerArray *gNonPanes;        /* list of ids of classes that may not be panes */
  455.  
  456.  
  457. extern pascal void InitUSizerView();
  458.         /* Initializes utility VRects and registers TSizerView */
  459.  
  460. extern pascal TView *CloneAView(TView *aView);
  461.         /* Clone aView and all its subviews */
  462.  
  463. extern pascal void ExcludeAsPane(TObject *obj);
  464.         /* Make the class of obj ineligible for pane-dom (i.e., add the class id of obj
  465.           to the gNonPanes list). */
  466.  
  467. #endif
  468.